package com.easyjob.controller;

import com.easyjob.annotation.GlobalInterceptor;
import com.easyjob.entity.dto.AppUserLoginDto;
import com.easyjob.entity.vo.QuestionInfoVo;
import com.easyjob.entity.vo.ResponseVO;
import com.easyjob.entity.vo.app.WrongQuestionVo;
import com.easyjob.service.QuestionInfoService;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController("PractiseController")
@RequestMapping("/practise")
public class PractiseController extends ABaseController{

    @Resource
    private QuestionInfoService questionInfoService;

    @RequestMapping("/getQuestionByChapterId")
    @GlobalInterceptor
    public ResponseVO getQuestionByChapterId(@RequestParam("id") Integer id) {
        List<QuestionInfoVo> questionInfoVoList = questionInfoService.getInfoByChapterId(id, 1);
        return getSuccessResponseVO(questionInfoVoList);
    }
    @RequestMapping("/getQuestionByCategoryId")
    @GlobalInterceptor
    public ResponseVO getQuestionByCategoryId(@RequestParam("categoryId") Integer id) {
        List<QuestionInfoVo> questionInfoVoList = questionInfoService.getInfoByCategoryId(id);
        return getSuccessResponseVO(questionInfoVoList);
    }

    @RequestMapping("/getWrongQuestionList")
    @GlobalInterceptor
    public ResponseVO getWrongQuestionList(@RequestHeader(value = "token") String token) {
        AppUserLoginDto appDto = getAppUserLoginInfoFromToken(token);
        List<WrongQuestionVo> questionInfoVoList = questionInfoService.getWrongQuestionList(appDto);
        return getSuccessResponseVO(questionInfoVoList);
    }
}
